package com.java.comprehensive.arithmetic.leecode.tags.queue;

import java.util.PriorityQueue;
import java.util.Queue;

/**
 * @Author: Dgg
 * @Date: 2021/12/15 22:36
 */
public class LeetCode_933 {

	static class RecentCounter {
		Queue<Integer> q;

		public RecentCounter() {
			q = new PriorityQueue();
		}

		public int ping(int t) {
			boolean offer = q.offer(t);
			System.out.println(offer);
			while (q.peek() < t - 3000) {
				q.poll();
			}
			return q.size();
		}

		public int ping2(int t) {
			q.add(t);
			while (q.peek() < t - 3000) {
				q.remove();
			}
			return q.size();
		}
	}

	public static void main(String[] args) {
		RecentCounter recentCounter = new RecentCounter();
		int ping = recentCounter.ping(1);// requests = [1]，范围是 [-2999,1]，返回 1
		int ping1 = recentCounter.ping(100);// requests = [1, 100]，范围是 [-2900,100]，返回 2
		int ping2 = recentCounter.ping(3001);// requests = [1, 100, 3001]，范围是 [1,3001]，返回 3
		int ping3 = recentCounter.ping(3002);// requests = [1, 100, 3001, 3002]，范围是 [2,3002]，返回 3
	}
}
